<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <p>输入数字并点击验证按钮:</p>
    <input id="id1" type="number" min="100" required />
    <button onclick="myFunction()">验证</button>

    <p>如果输入的数字小于 100 ( input 的 min 属性), 会显示错误信息。</p>

    <p id="demo"></p>

    <script>
      function myFunction() {
        var txt = "";
        var inpObj = document.getElementById("id1");
        if (!isNumeric(inpObj.value)) {
          txt = "你输入的不是数字";
        } else if (inpObj.validity.rangeUnderflow) {
          txt = "输入的值太小了";
        } else {
          txt = "输入正确";
        }
        document.getElementById("demo").innerHTML = txt;
      }

      // 判断输入是否为数字
      function isNumeric(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
      }
    </script>
  </body>
</html>
